package com.my.nio;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.nio.IntBuffer;

/**
 * @author mars
 * @date 2025-04-01 07:46
 */
@Slf4j
public class UseBuffer {
    @Test
    public void allocateTest() {
        try{
            // create buffer
            var buf = IntBuffer.allocate(20);
            // print buffer import attribute
            log.info("position = {}", buf.position());
            log.info("limit = {}", buf.limit());
            log.info("capacity = {}", buf.capacity());
            buf.put(10);
            buf.put(2, 80);
            log.info("position = {}", buf.position());
            log.info("limit = {}", buf.limit());

            buf.flip();
            log.info("value = {}", buf.get());
            log.info("position = {}", buf.position());
            log.info("limit = {}", buf.limit());
//            log.info("value = {}", buf.get());
            log.info("position = {}", buf.position());
            log.info("limit = {}", buf.limit());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }
}
